(function (vc) {
    vc.extends({
        data: {
            addServiceMenuInfo: {
                menuId: '',
                name: '',
                menuIcon: '',
                pageUrl: '',
                skipType: '1',
                seq: '',
                isShow: '',
                isShows: [],
                servId: '',
                housekeepingServs: []
            }
        },
        _initMethod: function () {
            vc.getDict('housekeeping_type', "is_show", function (_data) {
                $that.addServiceMenuInfo.isShows = _data;
            });
        },
        _initEvent: function () {
            vc.on('addServiceMenu', 'openAddServiceMenuModal', function () {
                $that._listHousekeepingServs();
                $('#addServiceMenuModel').modal('show');
            });
            vc.on("addServiceMenu", "notifyUploadCoverImage", function (_param) {
                if (_param.length > 0) {
                    $that.addServiceMenuInfo.menuIcon = _param[0].url;
                } else {
                    $that.addServiceMenuInfo.menuIcon = '';
                }
            });
        },
        methods: {
            addServiceMenuValidate() {
                return vc.validate.validate({
                    addServiceMenuInfo: $that.addServiceMenuInfo
                }, {
                    'addServiceMenuInfo.name': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "菜单名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "菜单名称名称太长"
                        },
                    ],
                    'addServiceMenuInfo.menuIcon': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "小图标不能为空"
                        }
                    ],

                    'addServiceMenuInfo.seq': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "排序不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "排序不是有效数字"
                        },
                    ],
                    'addServiceMenuInfo.isShow': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "是否显示不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "2",
                            errInfo: "是否显示格式错误"
                        },
                    ]
                });
            },
            saveServMenuInfo: function () {
                if (!$that.addServiceMenuValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addServiceMenuInfo.shopId = vc.getCurrentCommunity().shopId;

                ///pages/homemaking/detail?servId=112024122176700412&shopId=502024122060970108
                $that.addServiceMenuInfo.pageUrl = "/pages/homemaking/detail?shopId="
                    + vc.getCurrentCommunity().shopId
                    + "&servId=" + $that.addServiceMenuInfo.servId;
                vc.http.apiPost(
                    '/shopMenu.saveShopMenu',
                    JSON.stringify($that.addServiceMenuInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        vc.toast(_json.msg);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addServiceMenuModel').modal('hide');
                            $that.clearAddServiceMenuInfo();
                            vc.emit('indexMenu', 'listMenu', {});
                            return;
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            clearAddServiceMenuInfo: function () {
                $that.addServiceMenuInfo = {
                    menuId: '',
                    name: '',
                    menuIcon: '',
                    pageUrl: '',
                    skipType: '1',
                    seq: '',
                    isShow: '',
                    isShows: [],
                    servId: '',
                    housekeepingServs: []
                };
            },
            _listHousekeepingServs: function (_page, _rows) {
                let param = {
                    params: {
                        page:1,
                        row:100,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingServ.queryHousekeepingServ',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                     
                        $that.addServiceMenuInfo.housekeepingServs = _json.data;
                   
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);
